package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.EmployeeDeptRecord;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.DeptUtil;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import com.zrwl.poscloud.xo.mapper.GradeTeacherRMapper;
import com.zrwl.poscloud.xo.service.EmployeeRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.EmployeeDeptRecordMapper;
import com.zrwl.poscloud.xo.service.EmployeeDeptRecordService;
import com.zrwl.poscloud.xo.vo.EmployeeDeptRecordVO;

import javax.annotation.Resource;

/**
 * 人员机构变动 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-02-27
 */
@Service
public class EmployeeDeptRecordServiceImpl extends SuperServiceImpl<EmployeeDeptRecordMapper,EmployeeDeptRecord> implements EmployeeDeptRecordService {

    @Autowired
    private EmployeeDeptRecordService employeeDeptRecordService;
    @Resource
    private EmployeeDeptRecordMapper employeeDeptRecordMapper;
    @Override
    public IPage<EmployeeDeptRecordVO> getPageList(EmployeeDeptRecordVO employeeDeptRecordVO){
        if (StringUtils.isNotEmpty(employeeDeptRecordVO.getCompanyCode()) && !StringUtils.isEmpty(employeeDeptRecordVO.getCompanyCode().trim())) {
            employeeDeptRecordVO.setCompanyCode(DeptUtil.getLatestCompnay(employeeDeptRecordVO.getCompanyCode()));
        }
       Page<EmployeeDeptRecord> page = new Page<>();
        page.setCurrent(employeeDeptRecordVO.getCurrentPage());
        page.setSize(employeeDeptRecordVO.getPageSize());
       IPage<EmployeeDeptRecordVO> pageList = employeeDeptRecordMapper.getPageList(page, employeeDeptRecordVO);
       List<EmployeeDeptRecordVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<EmployeeDeptRecord> getAllList(EmployeeDeptRecordVO employeeDeptRecordVO){
        QueryWrapper<EmployeeDeptRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<EmployeeDeptRecord> list = employeeDeptRecordService.list(queryWrapper);
        return list;
}
    @Override
    public String add(EmployeeDeptRecordVO employeeDeptRecordVO){
        EmployeeDeptRecord entity = new EmployeeDeptRecord();
        BeanUtils.copyProperties(employeeDeptRecordVO, entity, SysConf.STATUS);
        entity.insert();
        employeeDeptRecordVO.setUid(entity.getUid());
//        if(employeeDeptRecordVO.generateResume()){//是否生成简历
//            EmployeeDeptRecordVO deptRecordVO = new EmployeeDeptRecordVO();
//           /* deptRecordVO.setChangeRecord();
//            employeeRecordService.add();*/
//        }
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(EmployeeDeptRecordVO employeeDeptRecordVO){
        EmployeeDeptRecord entity = employeeDeptRecordService.getById(employeeDeptRecordVO.getUid());
        BeanUtils.copyProperties(employeeDeptRecordVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(EmployeeDeptRecordVO employeeDeptRecordVO){
        EmployeeDeptRecord entity = employeeDeptRecordService.getById(employeeDeptRecordVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
